package per.wsj.okhttp;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

public class MyTypeToken<T> {
    final Type type;

    protected MyTypeToken() {
        this.type = getSuperclassTypeParameter(getClass());
    }

    static Type getSuperclassTypeParameter(Class<?> subclass) {
        Type superclass = subclass.getGenericSuperclass();
        if (superclass instanceof Class) {
            throw new RuntimeException("Missing type parameter.");
        }
        ParameterizedType parameterized = (ParameterizedType) superclass;
        return parameterized.getActualTypeArguments()[0];
    }
}
